using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace SAInterfaceLibrary.MSVCVersions
{
    class MSVC2008 : ConfigMSVCVersionInfo
    {
        public MSVC2008(string template_dir)
        {
            _name = "2008";
            _template_dir = template_dir + @"\2008";
        }

        /// <summary>
        /// Return true if we can find the 2005 unique registry entries
        /// </summary>
        override public bool IsOnMachine
        {
            get
            {
                return GetRawInstallDir() != null;
            }
        }

        /// <summary>
        /// See if we can find the directory where devenv should exist.
        /// </summary>
        /// <returns></returns>
        protected override string GetDirectory()
        {
            ///
            /// Make sure that 9.0 is installed on this machine. This is a little tricky, as you might imagine!
            /// 

            RegistryKey k90 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\9.0");
            if (k90 == null)
            {
                return null;
            }

            ///
            /// Getting the install name is a bit of a pain - we need to use the CLSID to do this
            /// 

            RegistryKey clsid = Registry.ClassesRoot.OpenSubKey(@"VisualStudio.accessor.9.0\shell\Open\Command");
            if (clsid == null)
            {
                return null;
            }

            string cmd = (string)clsid.GetValue("");
            if (cmd == null || cmd[0] != '"')
            {
                return null;
            }
            cmd = cmd.Substring(1);
            cmd = cmd.Substring(0, cmd.IndexOf(@"\devenv.exe"));
            return cmd;
        }
    }
}
